package com.weishuang.monitor.leader.commons.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.weishuang.monitor.leader.commons.enums.SCODE;
import com.weishuang.monitor.leader.commons.utils.UserUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * Create by IDEA
 *
 * @Author ： weishuang
 * DateTime  ： 2019-04-10 11:20
 */
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 444543488218968926L;
    /**
     * 删除状态 >=1为删除
     */
    private String status;

    /**
     * 创建者
     */
    @JsonIgnore
    private String createdBy;

    /**
     * 创建时间
     */
    @JsonIgnore
    private Date createdTime;

    /**
     * 更新者
     */
    @JsonIgnore
    private String updatedBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updatedTime;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Date getUpdatedTime() {
        return updatedTime;
    }

    public void setUpdatedTime(Date updatedTime) {
        this.updatedTime = updatedTime;
    }

    public void insertInit(){
        String userName = UserUtils.getUserId();
        insertInit(userName);
    }

    public void insertInit(String createBy){
        this.createdBy = createBy;
        this.updatedBy = createBy;
        this.createdTime = new Date();
        this.updatedTime = new Date();
        this.status = SCODE.SYS_STATUS_NORMAL.getValue();
    }

    public void updateInit(){
        String userName = UserUtils.getUserId();
        updateInit(userName);
    }

    public void updateInit(String updateBy){
        this.updatedBy = updateBy;
        this.updatedTime = new Date();
    }

    public void deleteInit(){
        String userName = UserUtils.getUserId();
        deleteInit(userName);
    }

    public void deleteInit(String updateBy) {
        this.updatedBy = updateBy;
        this.updatedTime = new Date();
        this.status = SCODE.STATUS_DELETE.getValue();
    }
}
